package com.jinkaimen.kqb.ui.activity;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ht.baselibs.ui.base.BaseActivity;
import com.jinkaimen.kqb.R;


/**
 * 关于我们
 */
public class AboutMineActivity extends BaseActivity {
    private RelativeLayout mToScore;
    private TextView tv_activity_versioncode;

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initTitleBar() {
        mTitleBarView.setLeftBtnIcon(R.mipmap.back)//
                .setTitleText("关于我们");
    }

    @Override
    protected int initContentView() {
        return R.layout.activity_about_mine;
    }

    @Override
    protected void initChildView() {
        mToScore = (RelativeLayout) findViewById(R.id.rl_activity_about_mine_to_score);
        tv_activity_versioncode = (TextView) findViewById(R.id.tv_activity_versioncode);
    }

    @Override
    protected void initChildData() {
        tv_activity_versioncode.setText("V"+getAppVersionName(AboutMineActivity.this));
    }

    @Override
    protected void setChildViewListener() {
        mToScore.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.rl_activity_about_mine_to_score:
                goToMarket(AboutMineActivity.this, getPackageName());
                break;
        }
    }

    public static void goToMarket(Context context, String packageName) {
        Uri uri = Uri.parse("market://details?id=" + packageName);
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        try {
            context.startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 返回当前程序版本名
     */
    public static String getAppVersionName(Context context) {
        String versionName = "";
        String versioncode = "";
        try {
            // ---get the package info---
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            versionName = pi.versionName;
            versioncode = pi.versionCode+"";
            if (versionName == null || versionName.length() <= 0) {
                return "";
            }
        } catch (Exception e) {
            Log.e("VersionInfo", "Exception", e);
        }
        return versionName;
    }

}
